#include <cstdio>
#include <cstring>

#define INF 1e9
#define eps 1e-6
typedef long long ll;

int n, a[50], x[50][50], y[50][50];
int b[50], bb[50], ans;

inline int max(int a, int b) { return a > b ? a : b; }

void check() {
    memset(bb, -1, sizeof(bb));
    for (int i = 1; i <= n; i++)
        if (b[i] == 1) // 是诚实人的前提
            for (int j = 1; j <= a[i]; j++)
                if (b[x[i][j]] != y[i][j])
                    return; // 这个诚实人的证言与暂定结果不符，矛盾
    int sum = 0;
    for (int i = 1; i <= n; i++)
        sum += b[i]; // 对合法情况计算答案
    if (ans < sum)
        ans = sum;
}

void dfs(int k) {
    if (k == n) {
        check();
        return;
    }
    for (int i = 0; i <= 1; i++) { // 暴力枚举每个人是否诚实
        b[k + 1] = i;
        dfs(k + 1);
    }
}

int main() {
	freopen("data.in", "r", stdin);
	freopen("stdanswet.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        for (int j = 1; j <= a[i]; j++)
            scanf("%d%d", &x[i][j], &y[i][j]);
    }
    dfs(0);
    printf("%d\n", ans);

    return 0;
}
